# Maintainer: Steve Jemens <sjemens@hotmail.com>

_realname=xlnt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.0
pkgrel=1
pkgdesc="User-friendly xlsx library for C++14 (mingw-w64)"
url="https://github.com/tfussell/xlnt"
license=('MIT')
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
              "unzip")
source=("${_realname}-${pkgver}.zip"::"https://github.com/tfussell/xlnt/archive/v${pkgver}.zip")
noextract=("${_realname}-${pkgver}.zip") # bsdtar fails extracting the symlinks
sha256sums=('27db56b53745bf40e94edc531eb54ef67a75a40c9acc47609f0d8c8950b46d4c')

prepare() {
  unzip -oq "${_realname}-${pkgver}.zip" -d ${srcdir}
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  for _static in "ON" "OFF"; do
    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G"MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DSTATIC=${_static} \
      -DTESTS=OFF \
      ../${_realname}-${pkgver}

    make
  done
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "source/libxlnt.a" "${pkgdir}${MINGW_PREFIX}/lib/libxlnt.a"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
